package com.mudalov.rec.dao.model.study;

import com.mudalov.rec.dao.interfaces.IClonable;
import java.io.Serializable;
import java.util.Date;

public class TestResult implements Serializable, IClonable<TestResult> {

	private static final long serialVersionUID = -8147620515075090583L;

	private Long id;
	
	private Test test;
	
	private int points;
	
	private boolean passed;

    private Date date;
	
	public TestResult() {}

    public TestResult(Test test) {
        this.test = test;
    }
	
	public TestResult(Test test, int points, boolean passed, Date date) {
		this.test = test;
		this.points = points;
		this.passed = passed;
        this.date = date;
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public Test getTest() {
		return test;
	}

	public void setTest(Test test) {
		this.test = test;
	}

	public int getPoints() {
		return points;
	}

	public void setPoints(int points) {
		this.points = points;
	}

	public boolean isPassed() {
		return passed;
	}

	public void setPassed(boolean passed) {
		this.passed = passed;
	}

    public Date getDate() {
        return date;
    }

    public void setDate(Date date) {
        this.date = date;
    }

    private String testName;

    public String getTestName() {
        return getTest() != null ? getTest().getName() : "";
    }

    public void setTestName(String testName) {
        // nothing to do
    }



	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		result = prime * result + (passed ? 1231 : 1237);
		result = prime * result + points;
		result = prime * result + ((test == null) ? 0 : test.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (!(obj instanceof TestResult))
			return false;
		TestResult other = (TestResult) obj;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		if (passed != other.passed)
			return false;
		if (points != other.points)
			return false;
		if (test == null) {
			if (other.test != null)
				return false;
		} else if (!test.equals(other.test))
			return false;
        if (date == null) {
			if (other.date != null)
				return false;
		} else if (!date.equals(other.date))
			return false;
		return true;
	}

    public TestResult getClone() {
        TestResult clone = new TestResult();
        clone.setId(this.getId());
        clone.setPassed(this.isPassed());
        clone.setPoints(this.getPoints());
        clone.setDate(this.getDate());
        clone.setTest(this.getTest().getClone());
        return clone;
    }
	
}
